<template>
  <div>
    <!-- 循环菜单 -->
    <div v-for="menu in menus" :key="menu.path">
      <!-- 当存在children时 -->
      <el-submenu
        v-if="menu.children && menu.children.length > 0"
        :index="menu.path"
      >
        <template slot="title">
          <i :class="menu.meta.icon"></i>
          <span :class="menuTitileDisplay">{{ menu.meta.title }}</span>
        </template>

        <navbar-item :menus="menu.children"></navbar-item>
      </el-submenu>
      <!-- 当不存在children时 -->
      <el-menu-item v-else :index="menu.path">
        <i :class="menu.meta.icon ? menu.meta.icon : 'el-icon-menu'"></i>
        <span slot="title" :class="menuTitileDisplay">{{
          menu.meta.title
        }}</span>
      </el-menu-item>
    </div>
  </div>
</template>

<script>
export default {
  name: "NavbarItem",
  data () {
    return {
      menuTitileDisplay: {
        menu_title: this.collapse
      }
    }
  },
  props: {
    menus: {
      type: Array,
      require: true
    },
    collapse: {
      type: Boolean,
      default: false
    }
  }
}
</script>

<style>
/* 取消菜单收缩后的小箭头 */
.el-menu-vertical-demo .el-icon-arrow-right {
  display: none !important;
}

/* 收缩后菜单标题 */
.menu_title {
  display: none;
}
</style>